package com.sykj.manage.web;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
 * 
 * @author 高志远
 *2018年9月13日下午5:45:11
 *类描述：组织机构[sys_dept控制类
 */
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sykj.manage.service.SysDeptService;
import com.sykj.manage.model.SysDept;
import com.sykj.util.ManageBody;
import com.sykj.util.PageUtil;
@Controller
@RequestMapping("/sys")
public class SysDeptController {
	
	@Autowired
	SysDeptService sysDeptService;
	/**
	 * 组织机构
	 * @param sysDept
	 * @return
	 */
	@RequestMapping("/findDepts")
	@ResponseBody
	public ManageBody findDepts(SysDept sysDept,Integer offset,Integer pageSize) {
		PageHelper.startPage(offset==null?1:PageUtil.getPageNum(offset, pageSize),pageSize==null?10:pageSize,true);
		List<SysDept> depts = sysDeptService.findDepts(sysDept);
		PageInfo<SysDept> pageInfo = new PageInfo<SysDept>(depts);
		return ManageBody.getData((int)pageInfo.getTotal(),pageInfo.getList(),"");
	}
	
	/**
	 * 删除组织机构
	 * @param menu_id
	 * @return
	 */
	@RequestMapping("/delDepts")
	@ResponseBody
	public Object delMenus(@RequestParam("dept_id")String[] dept_id) {
		int cnt = sysDeptService.delDepts(dept_id);
		return cnt;
	}
	/**
	 * 
	 * @param sysDept
	 * @return
	 * 
	 * 添加
	 */
	@RequestMapping("/addDept")
	@ResponseBody
	public Object addDept(SysDept sysDept){
		Date date = new Date();
		sysDept.setCreate_time(date);
		int addDept= sysDeptService.addDept(sysDept);
		return addDept;
		
	}
	
	/**
	 * @param dept_id
	 * @return
	 * 根据ID查询
	 */
	@RequestMapping("/findDeptById")
	@ResponseBody
	public Object findDeptById(String dept_id) {
		SysDept findDeptById = sysDeptService.findDeptById(dept_id);
		return findDeptById;
	}
	
	@RequestMapping("/updDept")
	@ResponseBody
	public Object updDept(SysDept sysDept){
		Date date = new Date();
		sysDept.setCreate_time(date);
		int updDept= sysDeptService.updDept(sysDept);
		return updDept;
		
	}
	
	@RequestMapping("/findDeptsName")
	@ResponseBody
	public Object findDeptsName(SysDept sysDept) {
		List<SysDept> findDepts = sysDeptService.findDepts(sysDept);
		return findDepts;
	}
	

}
